package com.tfy.liquor.controller;

import com.tfy.liquor.bean.Result;
import com.tfy.liquor.bean.UserShoppingAddress;
import com.tfy.liquor.service.UserShoppingAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/userShoppingAddress")
public class UserShoppingAddressController {
    @Autowired
    private UserShoppingAddressService userShoppingAddressService;

    // 添加收货地址信息
    @RequestMapping("/addUserShoppingAddress")
    public Result addUserShoppingAddress(UserShoppingAddress userShoppingAddress) {
//        System.err.println(userShoppingAddress);
        if (null == userShoppingAddress) {
            return new Result().bad_CodeIsNull();
        }
        if (userShoppingAddressService.addUserShoppingAddress(userShoppingAddress)) {
            return new Result().ok("添加成功！");
        }
        return new Result().error("添加失败！");
    }

    // 获取收货地址列表
    @RequestMapping("/getUserShoppingAddressByUserId")
    public Result getUserShoppingAddressByUserId(Long userId) {
        if (null == userId || userId < 0) {
            return new Result().bad_CodeIsNull();
        }
        return new Result(userShoppingAddressService.getUserShoppingAddressByUserId(userId)).ok();
    }

    // 停用收货地址
    @RequestMapping("/stopUserShoppingAddressById")
    public Result stopUserShoppingAddressById(UserShoppingAddress userShoppingAddress) {
        if (null == userShoppingAddress) {
            return new Result().bad_CodeIsNull();
        }
        if (userShoppingAddressService.stopUserShoppingAddressById(userShoppingAddress)) {
            return new Result().ok();
        }
        return new Result().error();
    }

    // 获取用户默认收货地址
    @RequestMapping("/getDefaultUserShoppingAddress")
    public Result getDefaultUserShoppingAddress(Long userId) {
        if (null == userId || userId < 0) {
            return new Result().bad_CodeIsNull();
        }
        return new Result(userShoppingAddressService.getDefaultUserShoppingAddress(userId)).ok();
    }
}
